package sql_film;

import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapreduce.lib.db.DBWritable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Movie_result implements DBWritable, Writable{
    private String name;
    private String actor;
    private double grade;
    private int num;
    private String common;

    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(name);
        dataOutput.writeUTF(actor);
        dataOutput.writeDouble(grade);
        dataOutput.writeInt(num);
        dataOutput.writeUTF(common);
    }

    public void readFields(DataInput dataInput) throws IOException {
        this.name = dataInput.readUTF();
        this.actor = dataInput.readUTF();
        this.grade = dataInput.readDouble();
        this.num = dataInput.readInt();
        this.common = dataInput.readUTF();
    }

    public void write(PreparedStatement statement) throws SQLException {
        statement.setString(1, this.name);
        statement.setString(2, this.actor);
        statement.setDouble(3, this.grade);
        statement.setInt(4, this.num);
        statement.setString(5, this.common);
    }

    public void readFields(ResultSet resultSet) throws SQLException {
        this.name = resultSet.getString(1);
        this.actor = resultSet.getString(2);
        this.grade = resultSet.getDouble(3);
        this.num = resultSet.getInt(4);
        this.common = resultSet.getString(5);
    }

    public void set(String name, String actor, double grade, int num, String common) {
        this.name = name;
        this.actor = actor;
        this.grade = grade;
        this.num = num;
        this.common = common;
    }

    @Override
    public String toString() {
        return "NewOutputFormatMapper{" +
                "name='" + name + '\'' +
                ", actor='" + actor + '\'' +
                ", grade=" + grade +
                ", num=" + num +
                ", common='" + common + '\'' +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getActor() {
        return actor;
    }

    public void setActor(String actor) {
        this.actor = actor;
    }

    public double getGrade() {
        return grade;
    }

    public void setGrade(double grade) {
        this.grade = grade;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public String getCommon() {
        return common;
    }

    public void setCommon(String common) {
        this.common = common;
    }
}
